
#pragma once

#include "type.h"

#include <vector>
#include <map>
#include <string>
#include <algorithm>
using namespace std;

class FrameAnimation;

#define RM								ResourceManager::getInstance()
#define CREATE_SPRITE(s)				RM->createSprite(s)
#define CREATE_SPRITEFRAME(s)			RM->createSpriteFrame(s)
#define T(s)							RM->getStringValue(s)

#define DEFAULT_BMP_FONT_NAME			"fonts/arial_20.fnt"

/*
    handle loading strings, game data
 */
class ResourceManager {
public:
    static ResourceManager* getInstance();
	virtual ~ResourceManager();

	void init();
	void reload();

	bool hasAnimationInfo(const string& key) {
		return animationInfos.find(key) != animationInfos.end();
	}
    
    const char* getStringValue(const char* key);

    Sprite* createSprite(const string& name);
	SpriteFrame* createSpriteFrame(const string& key);
    
    FrameAnimation * createAnimation(const string& animKey, const Point& location);
    
	MenuItemSprite *createButton(const char* spriteName, ccMenuCallback func, Node *parent);
	LabelTTF* createButtonLabelTTF(const char* text, Node* parent, int fontSize = 18);
	LabelBMFont* createButtonLabelBMFont(const char* text, Node* parent, const char* fontName = DEFAULT_BMP_FONT_NAME);
	void createBackground(Node* parent, const char* textureName);


	static string loadTextFile(const string& fileName);

private:
    static ResourceManager* _instance;
    ResourceManager();

	void loadAnimationData();
	void loadStrings(const char* locale = "us");

public:
	map<string, string> mapStrings;
	map<string, AnimationInfo> animationInfos;
};
